﻿using Furion.DependencyInjection;
using Lxb.Model;
using OTHMqttClient.model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OTHMqttClient.services
{
    public class Call_groupService : ITransient
    {
        private readonly ISqlSugarClient db;

        public Call_groupService(ISqlSugarClient db)
        {
            this.db = db.CopyNew();
        }

        public vcaller_group getsettting( string sn) {

            var sql = $"select lxb_caller_group.*,lxb_caller.teltype from  lxb_caller_group join lxb_caller on  lxb_caller_group.Group_id=lxb_caller.group_id where  lxb_caller.sn='{sn}'";
            var rlt=  db.Ado.SqlQuerySingle<vcaller_group>(sql);

            return rlt;
        }

        public bool cawx( int user_id)
        { 
        
          var sql = "SELECT count(m.uid) as ct  FROM   lxb_rel_huiyuan r   " +
                " JOIN lxb_member_oauth m ON r.UID = m.UID   " +
                " JOIN lxb_caller_user c ON c.openid = m.oauth_id   " +
                $" WHERE ruid = {user_id }   AND m.oauth_type = 'wxapp'";
            var rlt = db.Ado.SqlQuerySingle<int>(sql);

            return rlt >0;
        }

        public List<teles> teles(Users user)
        {
            string user_id = user.user_id.ToString();

           var lst=  db.Queryable<teles>().Where(t=>t.uid== user_id).ToList();
            if (lst.Count == 0) {

                lst.Add(new Lxb.Model.teles() { uid = user_id, name="默认", tel= user.tel });
            }

            return lst;
        }
    }
}
